package cn.itcast.mq.conf;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.FanoutExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.support.converter.Jackson2JsonMessageConverter;
import org.springframework.amqp.support.converter.MessageConverter;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class fanoutConfig {

    @Bean
    public MessageConverter jsonMessageConverter(){
        return new Jackson2JsonMessageConverter();
    }

    @Bean
    Queue fanoutQueue1(){

        return new Queue("fanout.queue1");
    }

    @Bean
    Queue fanoutQueue2(){

        return new Queue("fanout.queue2");
    }

    @Bean
    FanoutExchange fo(){
       return new FanoutExchange("nb.exchange");
    }

    @Bean
    Binding bd1(){
        return BindingBuilder.bind(fanoutQueue1()).to(fo());
    }
    @Bean
    Binding bd2(){
        return BindingBuilder.bind(fanoutQueue2()).to(fo());
    }
}
